import 'package:flutter/material.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/button_util.dart';
import 'package:xinxuan/common/dialogs/cancel_account_dialog.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:xinxuan/common/dialogs/del_dialog.dart';
import 'package:xinxuan/common/info_item.dart';
import 'package:xinxuan/common/dialogs/input_dialog_util.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/common/scroll_configuration_common.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/controllers/home_controller/home_page_controller.dart';
import 'package:xinxuan/controllers/my_controller/my_page_controller.dart';
import 'package:xinxuan/router/app_routers.dart';
import 'package:get/get.dart';
import 'package:xinxuan/utils/color_util.dart';

class MyInfoPage extends StatelessWidget {

  final CommonPageController commonPageController = Get.find();
  final MyPageController myPageController = Get.find();
  final HomePageController homePageController = Get.find();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      appBar: AppBarUtil(
        title: '个人信息',
        backgroundColor: pageBgColor,
      ),
      body: GetBuilder<CommonPageController>(
        builder: (controller) {
          return ScrollConfigurationCommon(child: ListView(
            children: [
              InfoItem(
                title: '头像', 
                child: NetworkImageUtil(
                  url: commonPageController.userData.value.avatar ?? '', 
                  nickname: '${commonPageController.userData.value.nickname}',
                  width: 50.w, 
                  height: 50.w,
                  borderRadius: 50.w,
                  showShadow: false,
                ), 
                showRigth: false,
                onTap: () {}
              ),
              InfoItem(
                title: '姓名', 
                child: Text(
                  '${commonPageController.userData.value.nickname}',
                  style: TextStyle(
                    color: textSubtitleColor,
                    fontSize: 16.sp
                  ),
                ), 
                onTap: () {
                  Get.dialog(StatefulBuilder(
                    builder: (context, setButtomSheetState) {
                      return InputDialogUtil(
                        title: '修改名称',
                        hintText: '请输入昵称',
                        defaultValue: '${commonPageController.userData.value.nickname}',
                        maxLength: 10,
                        onChenge: (value) {
                          commonPageController.nickname = value;
                        },
                        onSubmit: () {
                          commonPageController.editUserName();
                        }
                      );
                    }
                  ));
                }
              ),
              InfoItem(
                title: '手机号', 
                child: Text(
                  '${commonPageController.userData.value.mobile}',
                  style: TextStyle(
                    color: textSubtitleColor,
                    fontSize: 16.sp
                  ),
                ), 
                showRigth: false,
                onTap: () {}
              ),
              InfoItem(
                title: '收货地址', 
                child: Container(), 
                showBorder: false,
                onTap: () {
                  Get.toNamed(
                    '${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.ADDRESS_LIST_PAGE}',
                    arguments: {
                      'isSelectAddress': false
                    }
                  );
                }
              ),
              SizedBox(height: 12.h),
              InfoItem(
                title: '实名认证', 
                child: Container(), 
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.AUTHENTICATION_PAGE}');
                }
              ),
              InfoItem(
                title: '我的银行卡', 
                child: Container(), 
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.BANK_CARD_LIST_PAGE}');
                }
              ),
              InfoItem(
                title: '汇聚支付', 
                child: Container(), 
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.PAY_BANK_LIST_PAGE}');
                }
              ),
              InfoItem(
                title: '支付密码修改', 
                child: Container(), 
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.UPDATE_PAY_PASSWORD_PAGE}');
                }
              ),
              InfoItem(
                title: '登录密码修改', 
                child: Container(), 
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.UPDATE_PASSWORD_PAGE}');
                }
              ),
              SizedBox(height: 12.h),
              InfoItem(
                title: '我的微信号', 
                child: Container(), 
                onTap: () {
                  Get.dialog(StatefulBuilder(
                    builder: (context, setButtomSheetState) {
                      return InputDialogUtil(
                        title: '修改微信号',
                        hintText: '请输入微信号',
                        maxLength: 32,
                        defaultValue: '${commonPageController.userData.value.wechat}',
                        onChenge: (value) {
                          commonPageController.wechat = value;
                        },
                        onSubmit: () {
                          commonPageController.editUserWechat();
                        }
                      );
                    }
                  ));
                }
              ),
              InfoItem(
                title: '关于我们', 
                child: Container(), 
                showBorder: false,
                onTap: () {
                  Get.toNamed('${AppRouters.COMMON_PAGE}${AppRouters.MY_INFO_PAGE}${AppRouters.ABOUT_US_PAGE}');
                }
              ),
              SizedBox(height: 12.h),
              InfoItem(
                title: '版本更新', 
                child: Text(
                  '版本${commonPageController.appVersion}',
                  style: TextStyle(
                    color: textSubtitleColor,
                    fontSize: 16.sp
                  ),
                ), 
                onTap: () {
                  commonPageController.checkAppVersion();
                }
              ),
              SizedBox(height: 12.h),
              InfoItem(
                title: '注销账号', 
                child: Container(), 
                showBorder: false,
                onTap: () {
                  Get.dialog(CancelAccountDialog());
                }
              ),
              SizedBox(height: 12.h),
            ],
          ));
        },
      ),
      bottomNavigationBar: BottomAppBar(
        child: Container(
          height: 56.h,
          alignment: Alignment.center,
          padding: EdgeInsets.symmetric(horizontal: 12.w),
          child: ButtonUtil(
            text: '退出登录', 
            textColor: textBlackColor,
            bgColors: [
              pageBgColor,
              pageBgColor
            ],
            fontSize: 14.sp, 
            borderRadius: 18.w, 
            height: 36.h, 
            onTop: () {
              Get.dialog(DelDialog(title: '退出', message: '是否要退出登录？', onTap: () {
                myPageController.titleBarOpacity.value = 0.0;
                // homePageController.subHeight.value = 0;
                commonPageController.logOut();
              }));
            }
          ),
        ),
      ),
    );
  }
}